using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace SessionReportGenerator
{
    public class HtmlReportGenerator
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="HtmlReportGenerator"/> class.
        /// </summary>
        /// <param name="sessionStats">The session stats.</param>
        /// <param name="htmlTemplateFilename">The HTML template filename.</param>
        public HtmlReportGenerator(Dictionary<string, string> sessionStats, string htmlTemplateFilename)
        {
            this.sessionStats = sessionStats;
            this.htmlTemplateFilename = htmlTemplateFilename;
        }

        private Dictionary<string, string> sessionStats;
        private string htmlTemplateFilename;

        /// <summary>
        /// Generates the HTML report by reading the template file and replacing the stats codes with their respective values.
        /// </summary>
        /// <returns></returns>
        public string GenerateReport()
        {
            string template = File.ReadAllText(this.htmlTemplateFilename);

            foreach (KeyValuePair<string, string> currentStat in sessionStats)
            {
                template = Regex.Replace(template, @"\[" + currentStat.Key + @"\]", currentStat.Value);
            }

            return template;
        }
    }
}
